<!--标注关系使用 不要删除-->
<template>
  <el-dialog
    title="选择实体"
    :visible.sync="dialogVisible"
    width="400px"
    destroy-on-close
  >
    <el-radio-group v-model="entity">
      <el-radio
        style="display: block"
        :label="item"
        size="large"
        v-for="(item, index) in resultArr"
        :key="index"
        >{{ item.propertyName }}<img :src="item.entityName" class="imgStyle"
      /></el-radio>
    </el-radio-group>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">关 闭</el-button>
      <el-button type="primary" @click="createFun">创建关系</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: "DetailDialog",
  props: {},
  data() {
    return {
      id: "",
      dialogVisible: false,
      resultArr: [],
      entity: "",
      entityTypeId: "",
      entityId: "",
      img: "",
      label: "",
      relation: "",
      selectedCategoryId: "",
    };
  },

  methods: {
    cancel() {
      this.entity = "";
      this.dialogVisible = false;
    },
    show(data) {
      this.dialogVisible = true;
      this.resultArr = data.resultArr;
      this.entityTypeId = data.entityTypeId;
      this.entityId = data.entityId;
      this.img = data.img;
      this.label = data.label;
      this.selectedCategoryId = data.selectedCategoryId;
      this.id = data.id;
      this.relation = data.relationListInDom.find(
        (relation) => this.selectedCategoryId == relation.relationId
      );
    },
    createFun() {
      if (this.entity.entityTypeId != this.relation.tailId) {
        this.$message.warning(
          `当前实体不存在关系 "${this.relation.relationShowName}"`
        );

        return false;
      }
      let uuid = guid();
      // this.cancel();
      this.$emit("addNode", {
        data: {
          id: uuid,
          entityTypeId: this.entity.entityTypeId,
          relationId: this.relation.relationId,
          entityId: this.entity.entityId,
          label: this.entity.propertyName,
          img: this.entity.entityName,
          children: [],
        },
        id: this.id,
        relationArr: {
          id: uuid,
          headEntityId: this.entityId,
          tailEntityId: this.entity.entityId,
          relationTypeId: this.relation.relationId,
          //   id: relation.id,
          //   headEntityId: relation.startElement,
          //   tailEntityId: relation.endElement,
          //   relationTypeId: relation.relationTypeId.toString(),
        },
      });
      this.cancel();
    },
  },
};
function guid() {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
    let r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;

    return v.toString(16);
  });
}
</script>
<style scoped lang="scss">
.imgStyle {
  width: 30px;
  height: 30px;
  margin-left: 20px;
  position: relative;
  top: 10px;
}
</style>
